package com.sqkj.dao;

import com.sqkj.entity.Comment;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Mapper
public interface CommentDao {
    @Select("select * from comment where articleId = #{articleId}")
    @Results({
            @Result(column="userId",property="user",one=@One(
                    select="com.sqkj.dao.UserDao.findById",fetchType= FetchType.EAGER))
    })
    public List<Comment> findByArticleId(@Param("articleId")int articleId);


    @Insert("insert into comment(userId,articleId,comment,insertTime) values(#{userId},#{articleId},#{comment},#{insertTime})")
    @Transactional
    public int addComment(Comment comment);
}
